# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/symlink.gni")
import("//testing/test.gni")

if (is_android) {
  import("//build/config/android/rules.gni")
}

config("tools_config") {
  include_dirs = [
    "src",
    "src/third_party",
  ]
  if (is_android) {
    defines = [ "__ANDROID__" ]
  }
  if (is_clang) {
    cflags = [ "-Wno-tautological-constant-out-of-range-compare" ]
  }
}

config("internal_config") {
  include_dirs = [ "src" ]
  defines = []
  if (is_debug) {
    # This is needed for GTMLogger to work correctly.
    defines += [ "DEBUG" ]
  }
  if (is_android) {
    defines += [ "__ANDROID__" ]
  }
}

config("client_config") {
  include_dirs = [ "src" ]
  if (is_android) {
    include_dirs += [ "src/common/android/include" ]
  }
}

config("handler_config") {
  include_dirs = [ "src" ]
}

config("sender_config") {
  include_dirs = [ "src" ]
}

config("breakpad_unittest_config") {
  # One of the breakpad unit tests test that we can detect the proper build-id.
  # We must override the build-id for this one target.
  ldflags = [ "-Wl,--build-id=0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" ]
}

# {micro,mini}dump_stackwalk and minidump_dump are tool-type executables
# that do not build on Windows.
if (!is_win) {
  if (current_toolchain == host_toolchain) {
    # Contains the code shared by both {micro,mini}dump_stackwalk.
    static_library("stackwalk_common") {
      # Always want these files included regardless of platform.
      set_sources_assignment_filter([])
      sources = [
        "src/processor/basic_code_module.h",
        "src/processor/basic_code_modules.cc",
        "src/processor/basic_code_modules.h",
        "src/processor/basic_source_line_resolver.cc",
        "src/processor/call_stack.cc",
        "src/processor/cfi_frame_info.cc",
        "src/processor/cfi_frame_info.h",
        "src/processor/disassembler_x86.cc",
        "src/processor/disassembler_x86.h",
        "src/processor/dump_context.cc",
        "src/processor/dump_object.cc",
        "src/processor/logging.cc",
        "src/processor/logging.h",
        "src/processor/pathname_stripper.cc",
        "src/processor/pathname_stripper.h",
        "src/processor/proc_maps_linux.cc",
        "src/processor/process_state.cc",
        "src/processor/simple_symbol_supplier.cc",
        "src/processor/simple_symbol_supplier.h",
        "src/processor/source_line_resolver_base.cc",
        "src/processor/stack_frame_cpu.cc",
        "src/processor/stack_frame_symbolizer.cc",
        "src/processor/stackwalk_common.cc",
        "src/processor/stackwalker.cc",
        "src/processor/stackwalker_amd64.cc",
        "src/processor/stackwalker_amd64.h",
        "src/processor/stackwalker_arm.cc",
        "src/processor/stackwalker_arm.h",
        "src/processor/stackwalker_arm64.cc",
        "src/processor/stackwalker_arm64.h",
        "src/processor/stackwalker_mips.cc",
        "src/processor/stackwalker_mips.h",
        "src/processor/stackwalker_ppc.cc",
        "src/processor/stackwalker_ppc.h",
        "src/processor/stackwalker_ppc64.cc",
        "src/processor/stackwalker_ppc64.h",
        "src/processor/stackwalker_sparc.cc",
        "src/processor/stackwalker_sparc.h",
        "src/processor/stackwalker_x86.cc",
        "src/processor/stackwalker_x86.h",
        "src/processor/tokenize.cc",
        "src/processor/tokenize.h",

        # libdisasm
        "src/third_party/libdisasm/ia32_implicit.c",
        "src/third_party/libdisasm/ia32_implicit.h",
        "src/third_party/libdisasm/ia32_insn.c",
        "src/third_party/libdisasm/ia32_insn.h",
        "src/third_party/libdisasm/ia32_invariant.c",
        "src/third_party/libdisasm/ia32_invariant.h",
        "src/third_party/libdisasm/ia32_modrm.c",
        "src/third_party/libdisasm/ia32_modrm.h",
        "src/third_party/libdisasm/ia32_opcode_tables.c",
        "src/third_party/libdisasm/ia32_opcode_tables.h",
        "src/third_party/libdisasm/ia32_operand.c",
        "src/third_party/libdisasm/ia32_operand.h",
        "src/third_party/libdisasm/ia32_reg.c",
        "src/third_party/libdisasm/ia32_reg.h",
        "src/third_party/libdisasm/ia32_settings.c",
        "src/third_party/libdisasm/ia32_settings.h",
        "src/third_party/libdisasm/libdis.h",
        "src/third_party/libdisasm/qword.h",
        "src/third_party/libdisasm/x86_disasm.c",
        "src/third_party/libdisasm/x86_format.c",
        "src/third_party/libdisasm/x86_imm.c",
        "src/third_party/libdisasm/x86_imm.h",
        "src/third_party/libdisasm/x86_insn.c",
        "src/third_party/libdisasm/x86_misc.c",
        "src/third_party/libdisasm/x86_operand_list.c",
        "src/third_party/libdisasm/x86_operand_list.h",
      ]

      defines = [ "BPLOG_MINIMUM_SEVERITY=SEVERITY_ERROR" ]

      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]
      configs += [ ":tools_config" ]
    }

    executable("microdump_stackwalk") {
      sources = [
        "src/processor/microdump.cc",
        "src/processor/microdump_processor.cc",
        "src/processor/microdump_stackwalk.cc",
      ]

      deps = [
        ":stackwalk_common",
        "//build/config/sanitizers:deps",
      ]

      defines = [ "BPLOG_MINIMUM_SEVERITY=SEVERITY_ERROR" ]

      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]
      configs += [ ":tools_config" ]
    }

    executable("minidump_stackwalk") {
      sources = [
        "src/processor/exploitability.cc",
        "src/processor/minidump.cc",
        "src/processor/minidump_processor.cc",
        "src/processor/minidump_stackwalk.cc",
      ]

      deps = [
        ":stackwalk_common",
        "//build/config/sanitizers:deps",
      ]

      defines = [ "BPLOG_MINIMUM_SEVERITY=SEVERITY_ERROR" ]

      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]
      configs += [ ":tools_config" ]

      # Always want these files included regardless of platform.
      set_sources_assignment_filter([])
      sources += [
        "src/processor/exploitability_linux.cc",
        "src/processor/exploitability_linux.h",
        "src/processor/exploitability_win.cc",
        "src/processor/exploitability_win.h",
        "src/processor/symbolic_constants_win.cc",
        "src/processor/symbolic_constants_win.h",
      ]
    }

    executable("minidump_dump") {
      set_sources_assignment_filter([])
      sources = [
        "src/processor/basic_code_module.h",
        "src/processor/basic_code_modules.cc",
        "src/processor/basic_code_modules.h",
        "src/processor/dump_context.cc",
        "src/processor/dump_object.cc",
        "src/processor/logging.cc",
        "src/processor/logging.h",
        "src/processor/minidump.cc",
        "src/processor/minidump_dump.cc",
        "src/processor/pathname_stripper.cc",
        "src/processor/pathname_stripper.h",
        "src/processor/proc_maps_linux.cc",
      ]

      configs += [ ":tools_config" ]

      # There are some warnings in this code.
      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]

      deps = [
        "//build/config/sanitizers:deps",
      ]
    }
  } else {
    # Aliases for convenience.
    binary_symlink("microdump_stackwalk") {
      binary_label = ":$target_name($host_toolchain)"
    }
    binary_symlink("minidump_stackwalk") {
      binary_label = ":$target_name($host_toolchain)"
    }
    binary_symlink("minidump_dump") {
      binary_label = ":$target_name($host_toolchain)"
    }
  }
}

# Mac --------------------------------------------------------------------------

if (is_mac) {
  if (current_toolchain == host_toolchain) {
    # TODO(GYP) This should be only 64-bit on Mac. From .gypi:
    # Like ld, dump_syms needs to operate on enough data that it may
    # actually need to be able to address more than 4GB. Use x86_64.
    # Don't worry! An x86_64 dump_syms is perfectly able to dump
    # 32-bit files.
    executable("dump_syms") {
      sources = [
        "src/common/dwarf/bytereader.cc",
        "src/common/dwarf/dwarf2diehandler.cc",
        "src/common/dwarf/dwarf2reader.cc",
        "src/common/dwarf/elf_reader.cc",
        "src/common/dwarf/elf_reader.h",
        "src/common/dwarf_cfi_to_module.cc",
        "src/common/dwarf_cu_to_module.cc",
        "src/common/dwarf_line_to_module.cc",
        "src/common/language.cc",
        "src/common/mac/arch_utilities.cc",
        "src/common/mac/arch_utilities.h",
        "src/common/mac/dump_syms.cc",
        "src/common/mac/file_id.cc",
        "src/common/mac/macho_id.cc",
        "src/common/mac/macho_reader.cc",
        "src/common/mac/macho_utilities.cc",
        "src/common/mac/macho_walker.cc",
        "src/common/md5.cc",
        "src/common/module.cc",
        "src/common/stabs_reader.cc",
        "src/common/stabs_to_module.cc",
        "src/tools/mac/dump_syms/dump_syms_tool.cc",
      ]

      # For src/common/stabs_reader.h.
      defines = [ "HAVE_MACH_O_NLIST_H" ]
      include_dirs = [ "src/common/mac" ]

      # The DWARF utilities require -funsigned-char.
      cflags = [ "-funsigned-char" ]

      configs += [ ":internal_config" ]

      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]

      # dwarf2reader.cc uses dynamic_cast.
      configs -= [ "//build/config/compiler:no_rtti" ]
      configs += [ "//build/config/compiler:rtti" ]

      libs = [ "Foundation.framework" ]

      if (!is_debug) {
        # dump_syms crashes when built at -O1, -O2, and -O3.  It does
        # not crash at -Os.  To play it safe, dump_syms is always built
        # at -O0 until this can be sorted out.
        # http://code.google.com/p/google-breakpad/issues/detail?id=329
        configs -= [ "//build/config/compiler:default_optimization" ]
        cflags += [ "-O0" ]
      }

      deps = [
        "//build/config/sanitizers:deps",
      ]
    }

    executable("symupload") {
      sources = [
        "src/common/mac/HTTPMultipartUpload.m",
        "src/tools/mac/symupload/symupload.m",
      ]

      include_dirs = [ "src/common/mac" ]

      libs = [ "Foundation.framework" ]

      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]

      deps = [
        "//build/config/sanitizers:deps",
      ]
    }
  } else {
    binary_symlink("dump_syms") {
      binary_label = ":$target_name($host_toolchain)"
    }
    binary_symlink("symupload") {
      binary_label = ":$target_name($host_toolchain)"
    }
  }
}

if (is_mac) {
  static_library("utilities") {
    sources = [
      "src/client/mac/crash_generation/ConfigFile.mm",
      "src/client/mac/handler/breakpad_nlist_64.cc",
      "src/client/mac/handler/dynamic_images.cc",
      "src/client/mac/handler/minidump_generator.cc",
      "src/client/minidump_file_writer.cc",
      "src/common/convert_UTF.c",
      "src/common/mac/MachIPC.mm",
      "src/common/mac/arch_utilities.cc",
      "src/common/mac/bootstrap_compat.cc",
      "src/common/mac/file_id.cc",
      "src/common/mac/launch_reporter.cc",
      "src/common/mac/macho_id.cc",
      "src/common/mac/macho_utilities.cc",
      "src/common/mac/macho_walker.cc",
      "src/common/mac/string_utilities.cc",
      "src/common/md5.cc",
      "src/common/simple_string_dictionary.cc",
      "src/common/string_conversion.cc",
    ]

    configs += [ ":internal_config" ]

    # There are some warnings in this code.
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
  }

  executable("crash_inspector") {
    sources = [
      "src/client/mac/crash_generation/Inspector.mm",
      "src/client/mac/crash_generation/InspectorMain.mm",
    ]

    # TODO(GYP): 'mac_real_dsym': 1,

    include_dirs = [
      "src/client/apple/Framework",
      "src/common/mac",
      "src",
    ]
    libs = [
      "CoreServices.framework",
      "Foundation.framework",
    ]

    deps = [
      ":utilities",
      "//build/config/sanitizers:deps",
    ]
  }

  # TODO(GYP) this target has some mac_bundle_resources stuff.
  # executable("crash_report_sender") {
  # }
  group("crash_report_sender") {
  }

  config("breakpad_config") {
    include_dirs = [ "src/client/apple/Framework" ]
  }

  static_library("breakpad") {
    sources = [
      "src/client/mac/Framework/Breakpad.mm",
      "src/client/mac/Framework/OnDemandServer.mm",
      "src/client/mac/crash_generation/crash_generation_client.cc",
      "src/client/mac/crash_generation/crash_generation_client.h",
      "src/client/mac/handler/exception_handler.cc",
      "src/client/mac/handler/protected_memory_allocator.cc",
    ]

    configs += [ ":internal_config" ]
    public_configs = [ ":breakpad_config" ]

    defines = [ "USE_PROTECTED_ALLOCATIONS=1" ]
    include_dirs = [ "src/client/apple/Framework" ]

    deps = [
      ":crash_inspector",
      ":crash_report_sender",
      ":utilities",
    ]
  }

  group("client") {
    public_configs = [ ":client_config" ]
  }
}

if (is_linux || is_android) {
  if (current_toolchain == host_toolchain) {
    executable("symupload") {
      sources = [
        "src/common/linux/http_upload.cc",
        "src/common/linux/http_upload.h",
        "src/common/linux/symbol_upload.cc",
        "src/common/linux/symbol_upload.h",
        "src/tools/linux/symupload/sym_upload.cc",
      ]

      include_dirs = [
        "src",
        "src/third_party",
      ]

      configs += [ ":tools_config" ]

      libs = [ "dl" ]

      deps = [
        "//build/config/sanitizers:deps",
      ]
    }

    # dump_syms is a host tool, so only compile it for the host system.
    executable("dump_syms") {
      sources = [
        "src/common/dwarf/bytereader.cc",
        "src/common/dwarf/dwarf2diehandler.cc",
        "src/common/dwarf/dwarf2reader.cc",
        "src/common/dwarf/elf_reader.cc",
        "src/common/dwarf/elf_reader.h",
        "src/common/dwarf_cfi_to_module.cc",
        "src/common/dwarf_cfi_to_module.h",
        "src/common/dwarf_cu_to_module.cc",
        "src/common/dwarf_cu_to_module.h",
        "src/common/dwarf_line_to_module.cc",
        "src/common/dwarf_line_to_module.h",
        "src/common/language.cc",
        "src/common/language.h",
        "src/common/linux/crc32.cc",
        "src/common/linux/crc32.h",
        "src/common/linux/dump_symbols.cc",
        "src/common/linux/dump_symbols.h",
        "src/common/linux/elf_symbols_to_module.cc",
        "src/common/linux/elf_symbols_to_module.h",
        "src/common/linux/elfutils.cc",
        "src/common/linux/elfutils.h",
        "src/common/linux/file_id.cc",
        "src/common/linux/file_id.h",
        "src/common/linux/guid_creator.h",
        "src/common/linux/linux_libc_support.cc",
        "src/common/linux/linux_libc_support.h",
        "src/common/linux/memory_mapped_file.cc",
        "src/common/linux/memory_mapped_file.h",
        "src/common/module.cc",
        "src/common/module.h",
        "src/common/stabs_reader.cc",
        "src/common/stabs_reader.h",
        "src/common/stabs_to_module.cc",
        "src/common/stabs_to_module.h",
        "src/tools/linux/dump_syms/dump_syms.cc",
      ]

      # There are some warnings in this code.
      configs -= [ "//build/config/compiler:chromium_code" ]
      configs += [ "//build/config/compiler:no_chromium_code" ]

      # dwarf2reader.cc uses dynamic_cast. Because we don't typically
      # don't support RTTI, we enable it for this single target. Since
      # dump_syms doesn't share any object files with anything else,
      # this doesn't end up polluting Chrome itself.
      configs -= [ "//build/config/compiler:no_rtti" ]
      configs += [ "//build/config/compiler:rtti" ]

      # Breakpad rev 583 introduced this flag.
      # Using this define, stabs_reader.h will include a.out.h to
      # build on Linux.
      defines = [ "HAVE_A_OUT_H" ]

      include_dirs = [ "src" ]

      deps = [
        "//build/config/sanitizers:deps",
      ]
    }
  } else {
    # Aliases for convenience.
    binary_symlink("dump_syms") {
      binary_label = ":dump_syms($host_toolchain)"
    }
    binary_symlink("symupload") {
      binary_label = ":symupload($host_toolchain)"
    }
  }

  static_library("client") {
    # Want all these sources for both Linux and Android.
    set_sources_assignment_filter([])
    sources = [
      "src/client/linux/crash_generation/crash_generation_client.cc",
      "src/client/linux/crash_generation/crash_generation_client.h",
      "src/client/linux/dump_writer_common/mapping_info.h",
      "src/client/linux/dump_writer_common/thread_info.cc",
      "src/client/linux/dump_writer_common/thread_info.h",
      "src/client/linux/dump_writer_common/ucontext_reader.cc",
      "src/client/linux/dump_writer_common/ucontext_reader.h",
      "src/client/linux/handler/exception_handler.cc",
      "src/client/linux/handler/exception_handler.h",
      "src/client/linux/handler/minidump_descriptor.cc",
      "src/client/linux/handler/minidump_descriptor.h",
      "src/client/linux/log/log.cc",
      "src/client/linux/log/log.h",
      "src/client/linux/microdump_writer/microdump_writer.cc",
      "src/client/linux/microdump_writer/microdump_writer.h",
      "src/client/linux/minidump_writer/cpu_set.h",
      "src/client/linux/minidump_writer/directory_reader.h",
      "src/client/linux/minidump_writer/line_reader.h",
      "src/client/linux/minidump_writer/linux_core_dumper.cc",
      "src/client/linux/minidump_writer/linux_core_dumper.h",
      "src/client/linux/minidump_writer/linux_dumper.cc",
      "src/client/linux/minidump_writer/linux_dumper.h",
      "src/client/linux/minidump_writer/linux_ptrace_dumper.cc",
      "src/client/linux/minidump_writer/linux_ptrace_dumper.h",
      "src/client/linux/minidump_writer/minidump_writer.cc",
      "src/client/linux/minidump_writer/minidump_writer.h",
      "src/client/linux/minidump_writer/proc_cpuinfo_reader.h",
      "src/client/minidump_file_writer-inl.h",
      "src/client/minidump_file_writer.cc",
      "src/client/minidump_file_writer.h",
      "src/common/convert_UTF.c",
      "src/common/convert_UTF.h",
      "src/common/linux/elf_core_dump.cc",
      "src/common/linux/elf_core_dump.h",
      "src/common/linux/elfutils.cc",
      "src/common/linux/elfutils.h",
      "src/common/linux/file_id.cc",
      "src/common/linux/file_id.h",
      "src/common/linux/google_crashdump_uploader.cc",
      "src/common/linux/google_crashdump_uploader.h",
      "src/common/linux/guid_creator.cc",
      "src/common/linux/guid_creator.h",
      "src/common/linux/libcurl_wrapper.cc",
      "src/common/linux/libcurl_wrapper.h",
      "src/common/linux/linux_libc_support.cc",
      "src/common/linux/linux_libc_support.h",
      "src/common/linux/memory_mapped_file.cc",
      "src/common/linux/memory_mapped_file.h",
      "src/common/linux/safe_readlink.cc",
      "src/common/linux/safe_readlink.h",
      "src/common/memory.h",
      "src/common/simple_string_dictionary.cc",
      "src/common/simple_string_dictionary.h",
      "src/common/string_conversion.cc",
      "src/common/string_conversion.h",
    ]

    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
    public_configs = [ ":client_config" ]

    if (current_cpu == "arm" && is_chromeos) {
      # Avoid running out of registers in
      # linux_syscall_support.h:sys_clone()'s inline assembly.
      cflags = [ "-marm" ]
    }

    # Clang's -mstackrealign doesn't work well with
    # linux_syscall_support.h hand written asm syscalls.
    # See https://crbug.com/556393
    configs -= [ "//build/config/compiler:clang_stackrealign" ]

    if (is_android) {
      sources += [ "src/common/android/breakpad_getcontext.S" ]
    }

    libs = [ "dl" ]

    include_dirs = [
      ".",
      "src",
      "src/client",
      "src/third_party/linux/include",
    ]
  }

  static_library("processor_support") {
    set_sources_assignment_filter([])
    sources = [
      "src/common/scoped_ptr.h",
      "src/processor/basic_code_modules.cc",
      "src/processor/basic_code_modules.h",
      "src/processor/dump_context.cc",
      "src/processor/dump_object.cc",
      "src/processor/logging.cc",
      "src/processor/logging.h",
      "src/processor/minidump.cc",
      "src/processor/pathname_stripper.cc",
      "src/processor/pathname_stripper.h",
      "src/processor/proc_maps_linux.cc",
    ]

    include_dirs = [
      "src",
      "src/client",
      "src/third_party/linux/include",
      ".",
    ]

    # There are some warnings in this code.
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]
  }

  test("breakpad_unittests") {
    set_sources_assignment_filter([])
    sources = [
      "linux/breakpad_googletest_includes.h",
      "src/client/linux/handler/exception_handler_unittest.cc",
      "src/client/linux/minidump_writer/cpu_set_unittest.cc",
      "src/client/linux/minidump_writer/directory_reader_unittest.cc",
      "src/client/linux/minidump_writer/line_reader_unittest.cc",
      "src/client/linux/minidump_writer/linux_core_dumper_unittest.cc",
      "src/client/linux/minidump_writer/linux_ptrace_dumper_unittest.cc",
      "src/client/linux/minidump_writer/minidump_writer_unittest.cc",
      "src/client/linux/minidump_writer/minidump_writer_unittest_utils.cc",
      "src/client/linux/minidump_writer/proc_cpuinfo_reader_unittest.cc",
      "src/common/linux/elf_core_dump_unittest.cc",
      "src/common/linux/file_id_unittest.cc",
      "src/common/linux/linux_libc_support_unittest.cc",
      "src/common/linux/synth_elf.cc",
      "src/common/linux/tests/auto_testfile.h",
      "src/common/linux/tests/crash_generator.cc",
      "src/common/linux/tests/crash_generator.h",
      "src/common/memory_range.h",
      "src/common/memory_unittest.cc",
      "src/common/simple_string_dictionary_unittest.cc",
      "src/common/test_assembler.cc",
      "src/common/tests/file_utils.cc",
      "src/common/tests/file_utils.h",
      "src/tools/linux/md2core/minidump_memory_range.h",
      "src/tools/linux/md2core/minidump_memory_range_unittest.cc",
    ]

    deps = [
      ":client",
      ":linux_dumper_unittest_helper",
      ":processor_support",
      "//build/config/sanitizers:deps",
      "//testing/gmock",
      "//testing/gtest",
      "//testing/gtest:gtest_main",
    ]

    include_dirs = [
      "linux",  # Use our copy of breakpad_googletest_includes.h
      "src",
      ".",
    ]

    # There are some warnings in this code.
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]

    if (is_clang) {
      # See http://crbug.com/138571#c18
      cflags = [ "-Wno-unused-value" ]
    }

    if (is_android) {
      use_raw_android_executable = true
      sources += [ "src/common/android/breakpad_getcontext_unittest.cc" ]
      libs = [ "log" ]
      include_dirs += [ "src/common/android/include" ]
      extra_dist_files = [ "$root_out_dir/linux_dumper_unittest_helper" ]
    }

    # Clang's -mstackrealign doesn't work well with
    # linux_syscall_support.h hand written asm syscalls.
    # See https://crbug.com/556393
    configs -= [ "//build/config/compiler:clang_stackrealign" ]

    # Add the breakpad unittest config at the end to override all configs.
    configs += [ ":breakpad_unittest_config" ]
  }

  executable("linux_dumper_unittest_helper") {
    set_sources_assignment_filter([])
    testonly = true
    sources = [
      "src/client/linux/minidump_writer/linux_dumper_unittest_helper.cc",
    ]
    deps = [
      ":processor_support",
      "//build/config/sanitizers:deps",
    ]

    include_dirs = [ "src" ]

    if (current_cpu == "mipsel" && is_android) {
      include_dirs += [ "src/common/android/include" ]
    }
  }

  executable("generate_test_dump") {
    set_sources_assignment_filter([])
    testonly = true
    sources = [
      "linux/generate-test-dump.cc",
    ]

    # This file has an unused variable warning.
    configs -= [ "//build/config/compiler:chromium_code" ]
    configs += [ "//build/config/compiler:no_chromium_code" ]

    deps = [
      ":client",
      "//build/config/sanitizers:deps",
    ]

    include_dirs = [ "src" ]

    if (is_android) {
      libs = [ "log" ]
      include_dirs += [ "src/common/android/include" ]
    }
  }

  executable("minidump-2-core") {
    set_sources_assignment_filter([])
    sources = [
      "src/tools/linux/md2core/minidump-2-core.cc",
    ]

    include_dirs = [ "src" ]

    deps = [
      ":client",
      "//build/config/sanitizers:deps",
    ]
  }

  executable("core-2-minidump") {
    set_sources_assignment_filter([])
    sources = [
      "src/tools/linux/core2md/core2md.cc",
    ]

    deps = [
      ":client",
      "//build/config/sanitizers:deps",
    ]

    include_dirs = [ "src" ]
  }
}

if (is_ios) {
  static_library("client") {
    set_sources_assignment_filter([])
    sources = [
      "src/client/ios/Breakpad.h",
      "src/client/ios/Breakpad.mm",
      "src/client/ios/BreakpadController.h",
      "src/client/ios/BreakpadController.mm",
      "src/client/ios/handler/ios_exception_minidump_generator.h",
      "src/client/ios/handler/ios_exception_minidump_generator.mm",
      "src/client/mac/crash_generation/ConfigFile.h",
      "src/client/mac/crash_generation/ConfigFile.mm",
      "src/client/mac/handler/breakpad_nlist_64.cc",
      "src/client/mac/handler/breakpad_nlist_64.h",
      "src/client/mac/handler/dynamic_images.cc",
      "src/client/mac/handler/dynamic_images.h",
      "src/client/mac/handler/exception_handler.cc",
      "src/client/mac/handler/exception_handler.h",
      "src/client/mac/handler/minidump_generator.cc",
      "src/client/mac/handler/minidump_generator.h",
      "src/client/mac/handler/protected_memory_allocator.cc",
      "src/client/mac/handler/protected_memory_allocator.h",
      "src/client/mac/sender/uploader.h",
      "src/client/mac/sender/uploader.mm",
      "src/client/minidump_file_writer-inl.h",
      "src/client/minidump_file_writer.cc",
      "src/client/minidump_file_writer.h",
      "src/common/convert_UTF.c",
      "src/common/convert_UTF.h",
      "src/common/mac/GTMLogger.h",
      "src/common/mac/GTMLogger.m",
      "src/common/mac/HTTPMultipartUpload.m",
      "src/common/mac/file_id.cc",
      "src/common/mac/file_id.h",
      "src/common/mac/macho_id.cc",
      "src/common/mac/macho_id.h",
      "src/common/mac/macho_utilities.cc",
      "src/common/mac/macho_utilities.h",
      "src/common/mac/macho_walker.cc",
      "src/common/mac/macho_walker.h",
      "src/common/mac/string_utilities.cc",
      "src/common/mac/string_utilities.h",
      "src/common/md5.cc",
      "src/common/md5.h",
      "src/common/simple_string_dictionary.cc",
      "src/common/simple_string_dictionary.h",
      "src/common/string_conversion.cc",
      "src/common/string_conversion.h",
      "src/google_breakpad/common/minidump_format.h",
    ]
    set_sources_assignment_filter(sources_assignment_filter)

    include_dirs = [
      "src",
      "src/client/mac/Framework",
      "src/common/mac",
    ]

    public_configs = [ ":client_config" ]

    if (is_clang) {
      # See https://bugs.chromium.org/p/google-breakpad/issues/detail?id=675.
      cflags = [ "-Wno-deprecated-declarations" ]
    }
  }
  # TODO(GYP) There is some XCode-only targets like ninja-breakpad.
}

if (is_win) {
  group("client") {
    public_configs = [ ":client_config" ]
  }

  config("breakpad_handler_warnings") {
    if (is_clang) {
      # See https://code.google.com/p/google-breakpad/issues/detail?id=658.
      cflags = [ "-Wno-reorder" ]
    }
  }

  source_set("breakpad_handler") {
    configs += [ ":handler_config" ]
    if (is_win) {
      public_configs = [ ":handler_config" ]
    }

    defines = [ "BREAKPAD_NO_TERMINATE_THREAD" ]

    sources = [
      "src/client/windows/crash_generation/client_info.cc",
      "src/client/windows/crash_generation/client_info.h",
      "src/client/windows/crash_generation/crash_generation_client.cc",
      "src/client/windows/crash_generation/crash_generation_client.h",
      "src/client/windows/crash_generation/crash_generation_server.cc",
      "src/client/windows/crash_generation/crash_generation_server.h",
      "src/client/windows/crash_generation/minidump_generator.cc",
      "src/client/windows/crash_generation/minidump_generator.h",
      "src/client/windows/handler/exception_handler.cc",
      "src/client/windows/handler/exception_handler.h",
      "src/common/windows/guid_string.cc",
      "src/common/windows/guid_string.h",
      "src/common/windows/string_utils-inl.h",
      "src/google_breakpad/common/minidump_format.h",
    ]
    configs += [ ":breakpad_handler_warnings" ]
  }

  source_set("breakpad_sender") {
    sources = [
      "src/client/windows/sender/crash_report_sender.cc",
      "src/client/windows/sender/crash_report_sender.h",
      "src/common/windows/http_upload.cc",
      "src/common/windows/http_upload.h",
    ]
    configs += [ ":sender_config" ]
    public_configs = [ ":sender_config" ]
  }
}

if (is_android) {
  # TODO(GYP_GONE) Delete this after we've converted everything to GN.
  group("breakpad_unittests_deps") {
    testonly = true
    deps = [
      ":breakpad_unittests",
    ]
  }
}
